import { Login, logout, getInfo } from '@/api/admin/admin'
import { getToken, setToken, removeToken } from '@/utils/auth'
import {hasAllCT} from '@/api/system/call_type'
import {hasAllORS} from '@/api/system/other_regions'
import {hasAllOGR,hasAllToPageToC} from '@/api/system/operating_room'
import {hasAllC} from '@/api/system/courtyard'
import {hasAllByDepId,hasAllOR} from '@/api/system/operation_room'
import {hasByDepidWard} from '@/api/system/ward'
const getDefaultState = () => {
  return {
    token: getToken(),
    callType: null,
    avatar: ''
  }
}

const state = getDefaultState()

const mutations = {
  RESET_STATE: (state) => {
    Object.assign(state, getDefaultState())
  },
  SET_TOKEN: (state, token) => {
    state.token = token
  },
  SET_CALLTYPE: (state, callType) => {
    state.callType = callType
  },

}

const actions = {
  // user login
  callType({ commit }) {
    return new Promise((resolve, reject) => {
    hasAllCT().then(response => {
        commit('SET_CALLTYPE', response.data)
        resolve(response)
      }).catch(error => {
        reject(error)
        console.log(error)
      })
    })
  },
  //查询恢复室
  recoveryRoom({ commit },params) {
    return new Promise((resolve, reject) => {
      hasAllORS({type:2}).then(response => {
        // commit('SET_CALLTYPE', response.data)
        resolve(response)
      }).catch(error => {
        reject(error)
        console.log(error)
      })
    })
  },
  //根据type查询其他区域配置
  other_regions({ commit },params) {
    return new Promise((resolve, reject) => {
      if(params){
        hasAllORS(params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
      }else{
        hasAllORS().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
      }
      
    })
  },
  //查询院区
  courtyard({ commit },params) {
    return new Promise((resolve, reject) => {
      hasAllC().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
    })
  },
  //查询手术室、根据院区id
  operatingRoom({ commit },params) {
    return new Promise((resolve, reject) => {
      if(params){
        hasAllToPageToC(params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
      }else{
        hasAllOGR().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
      }
      
    })
  },
   //查询手术间，根据手术室id
  operationRoom({ commit },params) {
    return new Promise((resolve, reject) => {
      if(params){
        hasAllByDepId(params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
      }else{
        hasAllOR().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
      }
      
    })
    
  },
  //根据科室id查询病区
  Ward({ commit },params) {
    return new Promise((resolve, reject) => {
      if(params){
        hasByDepidWard(params).then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
      }else{
        hasAllOR().then(response => {
          resolve(response)
        }).catch(error => {
          reject(error)
          console.log(error)
        })
      }
      
    })
  }
  

  
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

